package com.koushikdutta.ion.bitmap;

public class Exif {
    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public static int getOrientation(byte[] r12, int r13, int r14) {
        /*
        if (r12 != 0) goto L_0x0004;
    L_0x0002:
        r9 = 0;
    L_0x0003:
        return r9;
    L_0x0004:
        r3 = 0;
        r2 = r13 + r14;
        r6 = r13;
    L_0x0008:
        r9 = r6 + 3;
        if (r9 >= r2) goto L_0x00fa;
    L_0x000c:
        r13 = r6 + 1;
        r9 = r12[r6];
        r9 = r9 & 255;
        r10 = 255; // 0xff float:3.57E-43 double:1.26E-321;
        if (r9 != r10) goto L_0x0033;
    L_0x0016:
        r9 = r12[r13];
        r5 = r9 & 255;
        r9 = 255; // 0xff float:3.57E-43 double:1.26E-321;
        if (r5 != r9) goto L_0x0020;
    L_0x001e:
        r6 = r13;
        goto L_0x0008;
    L_0x0020:
        r13 = r13 + 1;
        r9 = 216; // 0xd8 float:3.03E-43 double:1.067E-321;
        if (r5 == r9) goto L_0x00f7;
    L_0x0026:
        r9 = 1;
        if (r5 != r9) goto L_0x002b;
    L_0x0029:
        r6 = r13;
        goto L_0x0008;
    L_0x002b:
        r9 = 217; // 0xd9 float:3.04E-43 double:1.07E-321;
        if (r5 == r9) goto L_0x0033;
    L_0x002f:
        r9 = 218; // 0xda float:3.05E-43 double:1.077E-321;
        if (r5 != r9) goto L_0x0050;
    L_0x0033:
        r9 = 8;
        if (r3 <= r9) goto L_0x00f4;
    L_0x0037:
        r9 = 4;
        r10 = 0;
        r8 = pack(r12, r13, r9, r10);
        r9 = 1229531648; // 0x49492a00 float:823968.0 double:6.074693478E-315;
        if (r8 == r9) goto L_0x008f;
    L_0x0042:
        r9 = 1296891946; // 0x4d4d002a float:2.14958752E8 double:6.40749757E-315;
        if (r8 == r9) goto L_0x008f;
    L_0x0047:
        r9 = "CameraExif";
        r10 = "Invalid byte order";
        android.util.Log.e(r9, r10);
        r9 = 0;
        goto L_0x0003;
    L_0x0050:
        r9 = 2;
        r10 = 0;
        r3 = pack(r12, r13, r9, r10);
        r9 = 2;
        if (r3 < r9) goto L_0x005d;
    L_0x0059:
        r9 = r13 + r3;
        if (r9 <= r2) goto L_0x0066;
    L_0x005d:
        r9 = "CameraExif";
        r10 = "Invalid length";
        android.util.Log.e(r9, r10);
        r9 = 0;
        goto L_0x0003;
    L_0x0066:
        r9 = 225; // 0xe1 float:3.15E-43 double:1.11E-321;
        if (r5 != r9) goto L_0x008a;
    L_0x006a:
        r9 = 8;
        if (r3 < r9) goto L_0x008a;
    L_0x006e:
        r9 = r13 + 2;
        r10 = 4;
        r11 = 0;
        r9 = pack(r12, r9, r10, r11);
        r10 = 1165519206; // 0x45786966 float:3974.5874 double:5.758429993E-315;
        if (r9 != r10) goto L_0x008a;
    L_0x007b:
        r9 = r13 + 6;
        r10 = 2;
        r11 = 0;
        r9 = pack(r12, r9, r10, r11);
        if (r9 != 0) goto L_0x008a;
    L_0x0085:
        r13 = r13 + 8;
        r3 = r3 + -8;
        goto L_0x0033;
    L_0x008a:
        r13 = r13 + r3;
        r3 = 0;
        r6 = r13;
        goto L_0x0008;
    L_0x008f:
        r9 = 1229531648; // 0x49492a00 float:823968.0 double:6.074693478E-315;
        if (r8 != r9) goto L_0x00ae;
    L_0x0094:
        r4 = 1;
    L_0x0095:
        r9 = r13 + 4;
        r10 = 4;
        r9 = pack(r12, r9, r10, r4);
        r0 = r9 + 2;
        r9 = 10;
        if (r0 < r9) goto L_0x00a4;
    L_0x00a2:
        if (r0 <= r3) goto L_0x00b0;
    L_0x00a4:
        r9 = "CameraExif";
        r10 = "Invalid offset";
        android.util.Log.e(r9, r10);
        r9 = 0;
        goto L_0x0003;
    L_0x00ae:
        r4 = 0;
        goto L_0x0095;
    L_0x00b0:
        r13 = r13 + r0;
        r3 = r3 - r0;
        r9 = r13 + -2;
        r10 = 2;
        r0 = pack(r12, r9, r10, r4);
        r1 = r0;
    L_0x00ba:
        r0 = r1 + -1;
        if (r1 <= 0) goto L_0x00f4;
    L_0x00be:
        r9 = 12;
        if (r3 < r9) goto L_0x00f4;
    L_0x00c2:
        r9 = 2;
        r8 = pack(r12, r13, r9, r4);
        r9 = 274; // 0x112 float:3.84E-43 double:1.354E-321;
        if (r8 != r9) goto L_0x00ee;
    L_0x00cb:
        r9 = r13 + 8;
        r10 = 2;
        r7 = pack(r12, r9, r10, r4);
        switch(r7) {
            case 1: goto L_0x00df;
            case 2: goto L_0x00d5;
            case 3: goto L_0x00e2;
            case 4: goto L_0x00d5;
            case 5: goto L_0x00d5;
            case 6: goto L_0x00e6;
            case 7: goto L_0x00d5;
            case 8: goto L_0x00ea;
            default: goto L_0x00d5;
        };
    L_0x00d5:
        r9 = "CameraExif";
        r10 = "Unsupported orientation";
        android.util.Log.i(r9, r10);
        r9 = 0;
        goto L_0x0003;
    L_0x00df:
        r9 = 0;
        goto L_0x0003;
    L_0x00e2:
        r9 = 180; // 0xb4 float:2.52E-43 double:8.9E-322;
        goto L_0x0003;
    L_0x00e6:
        r9 = 90;
        goto L_0x0003;
    L_0x00ea:
        r9 = 270; // 0x10e float:3.78E-43 double:1.334E-321;
        goto L_0x0003;
    L_0x00ee:
        r13 = r13 + 12;
        r3 = r3 + -12;
        r1 = r0;
        goto L_0x00ba;
    L_0x00f4:
        r9 = 0;
        goto L_0x0003;
    L_0x00f7:
        r6 = r13;
        goto L_0x0008;
    L_0x00fa:
        r13 = r6;
        goto L_0x0033;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.koushikdutta.ion.bitmap.Exif.getOrientation(byte[], int, int):int");
    }

    private static int pack(byte[] bytes, int offset, int length, boolean littleEndian) {
        int step = 1;
        if (littleEndian) {
            offset += length - 1;
            step = -1;
        }
        int value = 0;
        int length2 = length;
        while (true) {
            length = length2 - 1;
            if (length2 <= 0) {
                return value;
            }
            value = (value << 8) | (bytes[offset] & 255);
            offset += step;
            length2 = length;
        }
    }
}
